import Mock from "mockjs";
import { param2Obj } from "../utils/myUtils";
// import { isNumber } from "../utils/base";
let List = [];
for (var i = 0; i < 200; i++) {
  List.push({
    id: i + 1,
    state: Mock.mock("@integer(0, 1)"),
    type: Mock.mock("@integer(0, 1)"),
    number: Mock.mock("@integer(100000, 200000)"),
    name: Mock.mock("@cname"),
    keshi: "全科",
    doctor: Mock.mock("@cname"),
    you: Mock.mock("@integer(200, 10)"),
    ying: Mock.mock("@integer(20000, 100)"),
    shi: Mock.mock("@integer(1000, 100)"),
    yi: Mock.mock("@integer(1000, 5000)"),
    hui: Mock.mock("@integer(0, 300)"),
    xian: Mock.mock("@integer(0, 1000)"),
    zhi: Mock.mock("@integer(50, 1111)"),
    wei: Mock.mock("@integer(110, 2331)"),
    yin: Mock.mock("@integer(660, 1444)"),
    date: Mock.mock("@datetime()"),
    person: Mock.mock("@cname"),
  });
}

// 搜索名字
export default {
  getChargeData: (config) => {
    // console.log("config", config);
    let { search, page, pageSize, type, date1, date2 } = param2Obj(config.url);
    // console.log(Date.parse("2022 / 01 / 07"));
    //名字，订单编号
    let newList = List.filter((item) => {
      if ((search + "").length == 6) {
        return (item.number + "").indexOf(search) != -1;
      } else {
        return item.name.indexOf(search) != -1;
      }
    });
    //订单类型
    let oldList = newList.filter((item) => {
      let typeObj = {
        处方开立: 0,
        不处方开立: 1,
      };
      if (type) {
        if (typeObj[type] == 1) {
          return item.type == 1;
        } else {
          return item.type == 0;
        }
      } else {
        return List;
      }
    });
    //日期筛选
    let dateList = oldList.filter((item) => {
      if (date1 && date2) {
        //判断输入框是否有值，有的话进if 没有进else
        let datee = Date.parse(item.date); //将数组里的时间，改成时间戳
        // console.log(date1, "date1===");
        // console.log(date2, "date2===");
        return datee > date1 && datee < date2;
      } else {
        return List;
      }
    });

    //分页
    let newList2 = dateList.filter((item, index) => {
      return (page - 1) * pageSize <= index && index < page * pageSize;
    });
    return {
      code: 200,
      msg: "请求成功",
      data: newList2,
    };
  },
};

// function searchType(search) {
//   if (isNumber(search)) {
//     return +search;
//   }
//   return search;
// }
// function getType(type) {
//   if (!type) return "";
//   return +type;
// }

// const AllMap = [getType(type), searchType(search)];
// let newList = [];
// if (AllMap.every((e) => e === "")) {
//   newList = List;
// } else {
//   newList = List.filter((item) => {
//     if(getType(type)&&searchType(search)){

//     }else if(getType(type)){

//     }else if(searchType(search)){

//     }
//   });
// }
